// 用户模型
const mongoose = require('mongoose')
const Schema = mongoose.Schema

const User = new mongoose.Schema({
  username: { type: String, required: true, unique, display: '昵称' },
  tell: { type: String, required: true, display: '电话号码' },
  tencent: {
    wechat: { type: String, required: true, display: '微信' },
    qq: { type: String, required: true, display: 'QQ' },
  },
  sex: { type: Number, required: true, default: 2, display: '性别' },
  previewImage: { type: [String], required: true, display: '用户头像' }, // 第一个为当前的头像
  group: { type: [Shema.Types.ObjectId], required: true, display: '用户组' },
  info: {
    identity: { type: String, required: require, display: '在校身份' },
    school: { type: String, display: '学校' },
    college: { type: String, display: '学院' },
    code: { type: String, display: '学号' },
    previewImage: { type: String, display: '证件照' }
  },
  coupon: { type: [{type: Schema.Types.ObjectId, required: true, display: '折扣券ID', ref: 'coupon'}], required: false, display: '用户折扣券' },
  state: { type: Number, required: true, default: 201, display: '状态[200:正常, 201:待审核, 404:已删除, 500:禁用]' },
  address: { type: Schema.Types.ObjectId, display: '默认收货地址' },
  identity: { type: String, display: '身份证号码' },
}, {
  collection: 'user',
  timestamps: {
    createAt: true,
    updateAt: true,
  },
})

let user = mongoose.model('user', User)

// 收货地址
let Address = new mongoose.Schema({
  uid: { type: Schema.Types.ObjectId, required: true, display: '用户ID'},
  desc: { type: String, required: false, display: '地址备注' },
  tell: { type: String, required: true, display: '收货人电话号码' },
  address: {
    province: { type: String, require: true, display: '省' },
    city: { type: String, require: true, display: '市' },
    county: { type: String, require: true, display: '县/区' },
    address: { type: String, require: true, display: '详细地址' },
  }
}, {
  collection: 'address',
  timestamps: {
    createAt: true,
    updateAt: true,
  }
})

let address = mongoose.model('address', Address)


module.exprts = {
  user: user,
  address: address,
}